<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ include file="/WEB-INF/jsp/component/common.jsp" %>
 <link href="${css}/bootstrap.min.css" rel="stylesheet"/>
 <link href="${css}/sb-admin-2.css" rel="stylesheet"/>
 <link href="${css}/patch.css" rel="stylesheet"/>
    
        <div class="modal-dialog" >
            <div class="modal-content">
            
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"> &times; </button>
                    <h4 class="modal-title">添加资源</h4>
                </div>
                
                <div class="modal-body">
                <form class="form-horizontal" role="form" id="addForm" name="resource" action="${ctx}/admin/mgmt/resource/save" method="post">
					<div class="form-body">
					<div class="form-group" id="add_name_div" >
						<label class="col-md-3 control-label">资源名称：</label>
						<div class="col-md-9">
							<input type="text" class="form-control  input-middel" name="name" id="add_name"/>
						</div>
					</div>
		            <div class="form-group" id="add_perm_div" >
						<label class="col-md-3 control-label">权限字符：</label>
						<div class="col-md-9">
							<input type="text" class="form-control  input-middel" name="perm" id="add_perm"/>
						</div>
					</div>
					<div class="form-group">
						<label class="col-md-3 control-label">连接：</label>
						<div class="col-md-9">
							<input type="text" class="form-control  input-middel" name="url" />
						</div>
					</div>
					<div class="form-group">
						<label class="col-md-3 control-label">父级资源：</label>
						<div class="col-md-9">
							<select id="pid" name="pid" class="form-control">
			                  <option value="0">--请选择--</option>
			                  <c:forEach items="${pList}" var="li">
			                    <option value="${li.id}">${li.name}</option>
			                  </c:forEach>
			               </select>
						</div>
					</div>
					<div class="form-group">
						<label class="col-md-3 control-label">资源类型：</label>
						<div class="col-md-9">
							<select id="type" name="type" class="form-control">
			                   <option value="0" >菜单</option>
			                   <option value="1" >操作按钮</option>
			                   <option value="2" >其他</option>
			               </select>
						</div>
					</div>
					<div class="form-group">
						<label class="col-md-3 control-label">是否启用：</label>
						<div class="col-md-9">
							<select id="available" name="available" class="form-control">
			                   <option value="0" >启用</option>
			                   <option value="1" >不启用</option>
			               </select>
						</div>
					</div>
					
					</div>
				</form>
                </div>
                
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary" id="addResource" onclick="SaveResource()" >保存</button>
                </div>
                
            </div>
        </div>
    
<link rel="stylesheet" href="${assets}/bootstrapValidator/css/bootstrapValidator.css"/>  
<script type="text/javascript" src="${assets}/bootstrapValidator/js/bootstrapValidator.js"></script>
<script type="text/javascript">
$(document).ready(function() {
    $('#addForm')
        .bootstrapValidator({
            message: 'This value is not valid',
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
            	roleName: {
                    message: '资源名称必须填写！',
                    validators: {
                        notEmpty: {
                            message: '资源名称不能为空！'
                        }
                    }
                },
                perm:{
                	message: '权限字符必须填写！',
                    validators: {
                        notEmpty: {
                            message: '权限字符不能为空！'
                        }
                    }
                }
            }
        });
});

//保存
function SaveResource(){
	var add_name = $("#add_name").val();
	var add_perm = $("#add_perm").val();
	if(add_name==null||add_name==""){
		bootbox.setLocale("zh_CN");
		bootbox.alert("请填写资源名称！");
	}else if(add_perm==null||add_perm==""){
		bootbox.setLocale("zh_CN");
		bootbox.alert("请填写权限字符！");
	}else{
		var url="${ctx}/admin/mgmt/resource/save?operate=add";
    	$.ajax({
    		type:"post",
    		url:url,
    		dataType:"html",
    	    data:$("#addForm").serialize(),
    	    success:function(result){
    	    	iframe1.window.selectData();
    	    	$("#dialog-Show").modal('hide');
    	    },
    	    error:function(data){
    	    	
    	    }
    	});
	}
}
</script>